const retUtil = {};

retUtil.numberFromCtx = (ctx, name) => {
    return Number(ctx.request.query[name] || ctx.request.body[name]) || 0;
};

retUtil.stringFromCtx = (ctx, name) => {
    return (ctx.request.query[name] || ctx.request.body[name] || '') + '';
};



retUtil.formatSuccessJson = (data) => {
    return {
        success: 1,
        msg: '成功',
        data: data || {}
    };
};

retUtil.formatErrorJson = (error) => {
    return {
        success: 0,
        msg: typeof error === 'string' ? error : '失败',
        data: {}
    };

};


module.exports = retUtil;